package cn.bocweb.spinning.view.dialog;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.Button;

import cn.bocweb.spinning.R;

/**
 * Created by chenchangxing on 15/12/23.
 */
public class ConnectServiceDialog extends AlertDialog implements View.OnClickListener {

    Context context;
    OnMakePhoneListener onMakePhoneListener;
    String number;


    public ConnectServiceDialog(Context context, String number) {
        super(context);
        this.number = number;
        this.context = context;
    }

    public ConnectServiceDialog(Context context, int themeResId, String number) {
        super(context, themeResId);
        this.number = number;
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_connect_service);

        Button btnSubmit = (Button) findViewById(R.id.btn_submit);
        Button btnCancel = (Button) findViewById(R.id.btn_cancel);

        btnSubmit.setOnClickListener(this);
        btnCancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_submit: {
                onMakePhoneListener.makePhone();
//                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number));
//
//                if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
//                    // TODO: Consider calling
//                    //    ActivityCompat#requestPermissions
//                    // here to request the missing permissions, and then overriding
//                    //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
//                    //                                          int[] grantResults)
//                    // to handle the case where the user grants the permission. See the documentation
//                    // for ActivityCompat#requestPermissions for more details.
//                    return;
//                }
//                context.startActivity(intent);
                break;
            }
            case R.id.btn_cancel: {
                dismiss();
                break;
            }
        }
    }

    public interface OnMakePhoneListener {
        void makePhone();
    }

    public void setOnMakePhoneListener(OnMakePhoneListener onMakePhoneListener) {
        this.onMakePhoneListener = onMakePhoneListener;
    }
}
